/**
 * Created by AlickChen on 2018/11/9.
 */
import axios from './axios'
import router from '../router/index'
import {showToast} from './index.js'
var myInterceptor=axios.interceptors.response.use(function (res) {
  if( res.data.data === 'no_login') {
    showToast(res.data.message,1500,'fail');
    if(is_weixn()){
        setTimeout(()=>{
           window.location.href="https://wx.zhaowea.com/api/auth/wechatLogin";
        },1500)
    }else {
        setTimeout(()=>{
            router.push({
                path: '/login',
                query: { redirect: router.currentRoute.fullPath}
            });
        },1500)
    }

  }
  return res
});



export function removeMyInterceptor(){
    axios.interceptors.response.eject(myInterceptor);

}
function is_weixn(){
    var ua = navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i)=="micromessenger") {
        return true;
    } else {
        return false;
    }
}

